<?php
//CONFIG//

// Enter your website title here
$sitename = "Lazygamerz";

// Enter API key here
$apikey = "odm54grtc23ha487rq";

// if you want to ban someone just do 1 => "usernmae" 
//where username is username and 1 is an incermental value
$banned = array();

//Enter custom news message
$news = "Alpha test";

// enter your variable descripts here:
$variable_desc = array(
    
    // Enter text that user will see for:
    // Being banned:
        "banned" => "You are banned from claiming rewards!",
    
    // Not supplying a username:
        "errorname" => "Please enter a username",
    
    // Not voted today
        "notvoted" => "You have not voted to be eligible for a reward!",
    
    // Getting the reward successfully
        "successfull" => "Thank you for voting, your reward will be given ASAP. :)"

);

//CONFIG END//

//load the xml file
$url = "http://starmade-servers.com/api/?object=servers&element=votes&key=".$apikey."&format=xml";
$xml = simplexml_load_file($url);

// init arrays for temprary holding of variables
$players = array();
$errors = array();
$success = array();

// set the timezone to UTC-0500H
date_default_timezone_set('America/New_York');

foreach ($xml->votes->vote as $key) {
        
        // convert the stanrdard full time to a timestamp like date
        $date = (int)date('Ymd', strtotime($key->date));
        
        // check if the player has voted today
        if ($date == (int)date('Ymd')) {
            
            // add eligable players to the players array
            $players[] = $key->nickname;
            
        }
        
}

 date_default_timezone_set('America/New_York');  
 
 if (isset($_POST['submit'])) {
     
     $username = $_POST['username'];
     
     if (isset($username) && $username != "") {
         //check if voted today
        if (in_array($username, $players)) {

            //check if banned
            if (in_array($username, $banned)) {

                $errors[] = $variable_desc['banned'];

            } else {

                // add to voted today list and give reward
                
                $success[] = $variable_desc['successfull'];
                
                // do random code crap here
                
            }

        } else {

            $errors[] = $variable_desc['notvoted'];

        }
        
     } else {
         
         $errors[] = $variable_desc['errorname'];
         
     }
     
 }

 function output_vars($vars) {
	return '
	<div class="" style="apadding-top:15px;">
	' . implode('</li><li>', $vars) . '
	</div>
	';
}

 function output_errors($vars) {
	return '
	<div class="alert-red alert-info-red" style="apadding-top:15px;">
	' . implode('</li><li>', $vars) . '
	</div>
	';
}

 function output_varsnl($vars) {
	return '
	<div class="" style="apadding-top:15px;">
	' . implode(' ', $vars) . '
	</div>
	';
}

?>
<html>
<head>
    <title><?php echo $sitename; ?> Rewards</title>
    <!-- insert more head tags because i was too lazy -->
</head>
<body>
<style>
html {
    background-color: #FFFFFF;
}
.alert-info {
    color: #3a87ad;
    background-color: #d9edf7;
    border-color: #bce8f1;
}
.alert {
    padding: 8px 35px 8px 14px;
    margin-bottom: 20px;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
    background-color: #E3FCF9;
    border: 1px solid #DBD5FB;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
}

.alert-info-red {
    color: #AD3A3A;
    background-color: #d9edf7;
    border-color: #bce8f1;
}
.alert-red {
    padding: 8px 35px 8px 14px;
    margin-bottom: 20px;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
    background-color: #FCE3E3;
    border: 1px solid #FBD5D5;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
}
</style>
<img src="/background.png." style="position: absolute; z-index: -999999;">
<div id="Logo">
    
</div>
<?php
if ($news != "") {
echo '<div class="alert alert-info">';
echo '<center><strong>News: </strong>'.$news.'</center>';
echo '</div>';
}     
?>        
<div id="players">
    The following players are eligible for rewards: <br /> 
    <?php echo output_varsnl($players); ?>
</div>
<form action="" method="POST">
    <h3><center>Warning: If you vote without being on server you will lose this reward!</center></h3>
    <h5><?php if (!empty($errors)) {echo output_errors($errors);}?></h5>
    <h5><?php if (!empty($success)) {echo output_vars($success);}?></h5>
    Username: <input type="text" name="username"> <br />
    <input type="submit" name="submit" value="Get Reward!">
</form>
<center>You can vote here to be eligible for a reward</center>
<object data=http://starmade-servers.com/server/689/vote/ width="100%" height="600"> <embed src=http://starmade-servers.com/server/689/vote/ width="100%" height="600"> </embed> Error: Embedded data could not be displayed. </object>
</body>
</html>